package cn.wolfcode.crm.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class BuyRecord {
    private Long id;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date inputTime;

    private Customer customer;

    private SystemDictionaryItem course;

    private BigDecimal money;

    public String getJsonData(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String inputTime = simpleDateFormat.format(this.inputTime);
        Map<String,Object> data = new HashMap<>();
        data.put("id",this.getId());
        data.put("inputTime",inputTime);
        data.put("money",this.money);
        data.put("customerId",this.getCustomer().getId());
        data.put("customerName",this.getCustomer().getName());
        data.put("courseId",this.getCourse().getId());
        data.put("courseName",this.getCourse().getTitle());
        return JSON.toJSONString(data);
    }


}